@echo off
REM Windows build script for AI-Powered SSH Terminal
REM Builds executable with optimizations for Windows deployment

echo ========================================
echo  AI-Powered SSH Terminal - Windows Build
echo ========================================

REM Check if in conda environment
if "%CONDA_DEFAULT_ENV%"=="" (
    echo WARNING: Not in a conda environment
    echo Recommended: conda activate ai-terminal
    echo.
)

REM Check if Python and PyInstaller are available
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: Python not found in PATH
    pause
    exit /b 1
)

python -c "import PyInstaller" >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: PyInstaller not installed
    echo Install with: pip install -r pyinstaller_requirements.txt
    pause
    exit /b 1
)

echo Building AI-Powered SSH Terminal for Windows...
echo.

REM Set build options
set BUILD_TYPE=dir
set INCLUDE_MODEL=false
set CREATE_PACKAGE=true

REM Parse command line arguments
:parse_args
if "%1"=="--onefile" (
    set BUILD_TYPE=onefile
    shift
    goto parse_args
)
if "%1"=="--include-model" (
    set INCLUDE_MODEL=true
    shift
    goto parse_args
)
if "%1"=="--no-package" (
    set CREATE_PACKAGE=false
    shift
    goto parse_args
)
if "%1"=="" goto build

:build
REM Clean previous builds
echo Cleaning previous builds...
if exist build rmdir /s /q build
if exist dist rmdir /s /q dist

REM Build executable
echo Starting build process...
python build_executable.py --build-type %BUILD_TYPE%

if %errorlevel% neq 0 (
    echo.
    echo ERROR: Build failed
    pause
    exit /b 1
)

REM Create package if requested
if "%CREATE_PACKAGE%"=="true" (
    echo.
    echo Creating distribution package...
    python build_executable.py --package
)

echo.
echo ========================================
echo  Build Complete!
echo ========================================
echo.
echo Executable location: dist\AI-Terminal\
echo.
echo To test the executable:
echo   cd dist\AI-Terminal
echo   AI-Terminal.exe
echo.

if "%CREATE_PACKAGE%"=="true" (
    echo Distribution package: AI-Terminal-Package\
    echo.
)

REM Ask if user wants to test immediately
set /p test="Test the executable now? (y/n): "
if /i "%test%"=="y" (
    echo.
    echo Starting AI-Terminal...
    cd dist\AI-Terminal
    start AI-Terminal.exe
    cd ..\..
)

pause